<?php
namespace Models\Model;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
use Zend\Db\Sql\Expression;
class ContactTable
{
    protected $tableGateway;
	protected $select;
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
		$this->select = new Select();
    }
	
	public function saveContactform($contactDetailes)
    {	
		
		$Sdate			=	$contactDetailes['startdate'];
		$SCreatedate 	= 	date_create($Sdate);
		$startdate 		= 	date_format($SCreatedate,'Y-m-d');
		
		$Edate			=	$contactDetailes['enddate'];
		$ECreatedate 	= 	date_create($Edate);
		$enddate 		= 	date_format($ECreatedate,'Y-m-d');
		$data = array(
			'course_name'				=> $contactDetailes['course_name'],
			'course_detailes'			=> $contactDetailes['course_detailes'],
			'firstname' 	  			=> $contactDetailes['firstname'],
			'lastname'					=> $contactDetailes['lastname'],
			'email' 					=> $contactDetailes['email'],			
			'phonenumber' 				=> $contactDetailes['phonenumber'],				
			'country' 					=> $contactDetailes['country'],				
			'city' 						=> $contactDetailes['city'],				
			'postcode' 					=> $contactDetailes['postcode'],			
			'address' 					=> $contactDetailes['address'],				
			'addressinfo' 				=> $contactDetailes['addressinfo'],			
			'startdate' 				=> $startdate ,				
			'enddate' 					=> $enddate,				
			'status' 					=> 1, 				
		);	
		$this->tableGateway->insert($data);	
		return $this->tableGateway->lastInsertValue;
    }
	public function updateAnswer($answer)
    {	
		
		if($answer['type']==0){
			$subjectId=0;
		}else{
		   $subjectId=$answer['subject_id'];
		}
		$data = array(
			'question_id'			=> $answer['question_id'],
			'subject_id'			=> $subjectId,
			'correct_answer' 	  	=> $answer['correct_answer'], 
			'level'					=> $answer['level'],
			'status' 				=> 1, 				
		);
		$updatedData=$this->tableGateway->update($data, array('question_id' => $answer['question_id']));
		return 	$updatedData;
    }
	
	public function getQuestionslist(){
		$select = $this->tableGateway->getSql()->select();
		$select->where('status="1"');
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;
	}
}